import { IPSAppCounterRef } from '../../app/control/ipsapp-counter-ref';
import { PSControlContainerImpl } from '../pscontrol-container-impl';
import { IPSSearchBarFilter } from './ipssearch-bar-filter';
import { IPSSearchBarGroup } from './ipssearch-bar-group';
import { IPSSearchBarQuickSearch } from './ipssearch-bar-quick-search';
import { IPSSysSearchBar } from './ipssys-search-bar';

export class PSSysSearchBarImpl extends PSControlContainerImpl implements IPSSysSearchBar {
  get codeName(): string {
    return this.M.codeName;
  }

  get groupMoreText(): string {
    return this.M.groupMoreText;
  }

  protected psappcounterref: IPSAppCounterRef | null = null;

  getPSAppCounterRef(): IPSAppCounterRef | null {
    if (this.psappcounterref != null) return this.psappcounterref;
    const value = this.M.getPSAppCounterRef;
    if (value == null) {
      return null;
    }
    this.psappcounterref = this.getPSModel4('app.control.IPSAppCounterRef', value, 'getPSAppCounterRef') as IPSAppCounterRef;
    return this.psappcounterref;
  }

  get psAppCounterRef(): IPSAppCounterRef | null {
    return this.getPSAppCounterRef();
  }

  getPSAppCounterRefMust(): IPSAppCounterRef {
    const value = this.getPSAppCounterRef();
    if (value == null) {
      throw new Error('未指定应用计数器引用');
    }
    return value;
  }

  protected pssearchbarfilters: IPSSearchBarFilter[] | null = null;

  getPSSearchBarFilters(): IPSSearchBarFilter[] | null {
    if (this.pssearchbarfilters == null) {
      this.pssearchbarfilters = this.fillChildListModel(this.M.getPSSearchBarFilters, 'control.searchbar.IPSSearchBarFilter') as IPSSearchBarFilter[];
    }
    return this.pssearchbarfilters;
  }

  get psSearchBarFilters(): IPSSearchBarFilter[] | null {
    return this.getPSSearchBarFilters();
  }

  findPSSearchBarFilter(objKey: any): IPSSearchBarFilter | null {
    return this.getPSModel5('control.searchbar.IPSSearchBarFilter', this.getPSSearchBarFilters(), objKey) as IPSSearchBarFilter;
  }

  protected pssearchbargroups: IPSSearchBarGroup[] | null = null;

  getPSSearchBarGroups(): IPSSearchBarGroup[] | null {
    if (this.pssearchbargroups == null) {
      this.pssearchbargroups = this.fillChildListModel(this.M.getPSSearchBarGroups, 'control.searchbar.IPSSearchBarGroup') as IPSSearchBarGroup[];
    }
    return this.pssearchbargroups;
  }

  get psSearchBarGroups(): IPSSearchBarGroup[] | null {
    return this.getPSSearchBarGroups();
  }

  findPSSearchBarGroup(objKey: any): IPSSearchBarGroup | null {
    return this.getPSModel5('control.searchbar.IPSSearchBarGroup', this.getPSSearchBarGroups(), objKey) as IPSSearchBarGroup;
  }

  protected pssearchbarquicksearchs: IPSSearchBarQuickSearch[] | null = null;

  getPSSearchBarQuickSearchs(): IPSSearchBarQuickSearch[] | null {
    if (this.pssearchbarquicksearchs == null) {
      this.pssearchbarquicksearchs = this.fillChildListModel(this.M.getPSSearchBarQuickSearchs, 'control.searchbar.IPSSearchBarQuickSearch') as IPSSearchBarQuickSearch[];
    }
    return this.pssearchbarquicksearchs;
  }

  get psSearchBarQuickSearchs(): IPSSearchBarQuickSearch[] | null {
    return this.getPSSearchBarQuickSearchs();
  }

  findPSSearchBarQuickSearch(objKey: any): IPSSearchBarQuickSearch | null {
    return this.getPSModel5('control.searchbar.IPSSearchBarQuickSearch', this.getPSSearchBarQuickSearchs(), objKey) as IPSSearchBarQuickSearch;
  }

  get quickGroupCount(): number {
    return this.M.quickGroupCount;
  }

  get quickSearchMode(): 0 | 1 | 2 {
    return this.M.quickSearchMode;
  }

  get quickSearchWidth(): number {
    return this.M.quickSearchWidth;
  }

  get searchBarStyle(): 'SEARCHBAR' | 'SEARCHBAR2' | 'MOBSEARCHBAR' | 'MOBSEARCHBAR2' | 'USER' | 'USER2' {
    return this.M.searchBarStyle;
  }

  get enableFilter(): boolean {
    return this.M.enableFilter;
  }

  get enableGroup(): boolean {
    return this.M.enableGroup;
  }

  get enableQuickSearch(): boolean {
    return this.M.enableQuickSearch;
  }

  get mobileSearchBar(): boolean {
    return this.M.mobileSearchBar;
  }

  get cls(): string {
    return 'PSSysSearchBarImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'control.IPSControl' || cls == 'control.searchbar.IPSSearchBar' || cls == 'control.searchbar.IPSSysSearchBar') return true;
    return super.instanceof(cls);
  }
}
